package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.*;
import com.sc.nft.entity.vo.ecology.EcologyReforgeTimeVO;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.EcologyReforgeConf;
import com.sc.nft.entity.EcologyReforgeExpendConf;
import com.sc.nft.entity.vo.AdminSimpleReforgeCollectionVO;
import com.sc.nft.entity.vo.ecology.*;
import com.sc.nft.service.AdminEcologyReforgeConfService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/ecology/reforge")
@Api(tags = "后台生态重铸配置管理")
public class AdminEcologyReforgeConfController {


    private final AdminEcologyReforgeConfService adminEcologyReforgeConfService;


    @PostMapping(value = "/addAndUpdateReforgeConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增或者修改生态重铸配置", notes = "新增生态重铸配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addAndUpdateReforgeConf(@Valid @RequestBody AddAndUpdateReforgeConfRequest request) {
        EcologyReforgeConf ecologyReforgeConf = BeanUtil.copyProperties(request, EcologyReforgeConf.class);
        List<EcologyReforgeExpendConf> expendConfList = BeanUtil.copyToList(request.getExpendList(), EcologyReforgeExpendConf.class);
        adminEcologyReforgeConfService.addAndUpdateReforgeConf(ecologyReforgeConf,expendConfList);
        return Result.success();
    }


    @PostMapping(value = "/getPageReforgeConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分页获取生态重铸配置", notes = "分页获取生态重铸配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminGetPageReforgeConfVO> getPageReforgeConf(@Valid @RequestBody GetPageReforgeConfRequest request) {
        return PageResult.success(adminEcologyReforgeConfService.getPageReforgeConf(request.getCollectionName(),request.getPageNo(),request.getPageSize()));
    }

    @PostMapping(value = "/getReforgeConfDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取生态重铸配置详情", notes = "获取生态重铸配置详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AdminReforgeConfDetailsVO> getReforgeConfDetails(@Valid @RequestBody IdRequest request) {
        return Result.success(adminEcologyReforgeConfService.getReforgeConfDetails(request.getId()));
    }

    @PostMapping(value = "/delExpendById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除生态重铸消耗配置", notes = "删除生态重铸消耗配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result delExpendById(@Valid @RequestBody IdRequest request) {
        adminEcologyReforgeConfService.delExpendById(request.getId());
        return Result.success();
    }

    @PostMapping(value = "/updateReforgeConfStatusById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "重铸配置上下架", notes = "重铸配置上下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateReforgeConfStatusById(@Valid @RequestBody StatusRequest request) {
        adminEcologyReforgeConfService.updateReforgeConfStatusgById(request.getId(),request.getStatus());
        return Result.success();
    }

    @PostMapping(value = "/updateReforgeConfSortById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "重铸配置排序", notes = "重铸配置排序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateReforgeConfSortById(@Valid @RequestBody SortRequest request) {
        adminEcologyReforgeConfService.updateReforgeConfSortById(request.getId(),Long.valueOf(request.getSort()));
        return Result.success();
    }

    @PostMapping(value = "/delReforgeConfById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除生态重铸配置", notes = "删除生态重铸配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result delReforgeConfById(@Valid @RequestBody IdRequest request) {
        adminEcologyReforgeConfService.delReforgeConfById(request.getId());
        return Result.success();
    }

    @PostMapping(value = "/getPageUserRecords", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户重铸记录奖励", notes = "用户熔炼记录奖励", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminEcologyReforgeUserRecordsVO> getPageUserRecordsRecords(@Valid @RequestBody UserEcologyHatchRcordsReuqest request) {
        return PageResult.success(adminEcologyReforgeConfService.getPageUserRecordsRecords(request.getCollectionName(),request.getUserTel(),request.getStartTime(),request.getEndTime(),request.getPageNo(),request.getPageSize()));
    }

    @PostMapping(value = "/getPageUserRecordsExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户重铸记录奖励导出", notes = "用户熔炼记录奖励导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminEcologyReforgeUserRecordsVO>> getPageUserRecordsExport(@Valid @RequestBody UserEcologyHatchRcordsReuqest request) {
        return Result.success(adminEcologyReforgeConfService.getPageUserRecordsExport(request.getCollectionName(),request.getUserTel(),request.getStartTime(),request.getEndTime()));
    }


    @PostMapping(value = "/userEcologyReforgeUpperLimitDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户重铸上限记录(汇总)", notes = "用户重铸上限记录(汇总)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminUserEcologyReforgeUpperLimitDetailsVO>> userEcologyReforgeUpperLimitDetails(@Valid @RequestBody AdminUserTelRequest request) {
        return Result.success(adminEcologyReforgeConfService.userEcologyReforgeUpperLimitDetails(request.getUserTel()));
    }

    @PostMapping(value = "/userEcologyReforgeUpperLimitPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户重铸上限记录(明细)", notes = "用户重铸上限记录(明细)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminUserEcologyReforgeUpperLimitPageVO> userEcologyReforgeUpperLimitPage(@Valid @RequestBody UserEcologyReforgeUpperLimitPageRequest request) {
        return PageResult.success(adminEcologyReforgeConfService.userEcologyReforgeUpperLimitPage(request.getUserId(),request.getCollectionId(),request.getBeginTime(),request.getEndTime(),request.getPageNo(),request.getPageSize()));
    }


    @PostMapping(value = "/getSimplePage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "简单的重铸藏品列表", notes = "简单的重铸藏品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminSimpleReforgeCollectionVO> getSimplePage(@Valid @RequestBody PageRequest request) {
        return PageResult.success(adminEcologyReforgeConfService.getSimplePage(request.getPageNo(),request.getPageSize()));
    }

    @ApiOperation(value = "重铸时间配置", notes = "重铸时间配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/time", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result time(@Valid @RequestBody EcologyReforgeTimeRequest request){
        adminEcologyReforgeConfService.timeConfig(request.getStartTime(), request.getEndTime(),request.getRemark());
        return Result.success();
    }

    @ApiOperation(value = "重铸时间详情", notes = "重铸时间详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/timeDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<EcologyReforgeTimeVO> timeDetail(){
        return Result.success(adminEcologyReforgeConfService.timeDetail());
    }
}
